package edu.gatech.cs2340.OregonTrail;

import javax.swing.*;


import edu.gatech.cs2340.OregonTrail.EventSystem.CommCoordinator;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;


/**
 * This is the river gui panel. 
 * @author Won Taek Chung
 * @version 1.0.1
 */
public class RiverPanel extends JPanel {


	private static final long serialVersionUID = 1L;
	
	//private OregonTrailApp parentFrame;
	//private CommCoordinator comm;
	private JButton btnCrossRiver;
	private Game game;
	//private int fee;
	private final ButtonGroup radioButtonGroup = new ButtonGroup();
	private JRadioButton rdbtnFord;
	private JRadioButton rdbtnCaulk;
	private JRadioButton rdbtnFerry;
	private JButton btnMenu;
	//private Random generator;
	//private Object[] itemList;
	//private Map<Item, Integer> playerStock;
	//private int chance;
	//private int numToRemove;
	//private Item toRemove;
	//private River currentRiver;
	
	public RiverPanel(final OregonTrailApp parentFrame, CommCoordinator comm, final River currentRiver)
	{
				//this.parentFrame = parentFrame;
				//this.comm = comm;
				//this.currentRiver = currentRiver;
				this.game = parentFrame.getGame();
				//this.fee = 100;

				//Generates buttons
				setPreferredSize(new Dimension(524, 600));
				GridBagLayout gridBagLayout = new GridBagLayout();
				gridBagLayout.columnWidths = new int[]{110, 300, 110, 0};
				gridBagLayout.rowHeights = new int[]{30, 30, 75, 0, 0, 0, 75, 0, 30, 0};
				gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
				gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
				setLayout(gridBagLayout);
				
				JLabel lblRiverCrossing = new JLabel("River Crossing");
				GridBagConstraints gbc_lblRiverCrossing = new GridBagConstraints();
				gbc_lblRiverCrossing.insets = new Insets(0, 0, 5, 5);
				gbc_lblRiverCrossing.gridx = 1;
				gbc_lblRiverCrossing.gridy = 1;
				add(lblRiverCrossing, gbc_lblRiverCrossing);
				
				rdbtnFord = new JRadioButton("Ford the river");
				GridBagConstraints gbc_rdbtnFordTheRiver = new GridBagConstraints();
				gbc_rdbtnFordTheRiver.anchor = GridBagConstraints.WEST;
				gbc_rdbtnFordTheRiver.insets = new Insets(0, 0, 5, 5);
				gbc_rdbtnFordTheRiver.gridx = 1;
				gbc_rdbtnFordTheRiver.gridy = 3;
				add(rdbtnFord, gbc_rdbtnFordTheRiver);
				radioButtonGroup.add(rdbtnFord);
				rdbtnFord.setSelected(true);
				
				rdbtnCaulk = new JRadioButton("Caulk the wagon and float it across");
				GridBagConstraints gbc_rdbtnCaulk = new GridBagConstraints();
				gbc_rdbtnCaulk.anchor = GridBagConstraints.WEST;
				gbc_rdbtnCaulk.insets = new Insets(0, 0, 5, 5);
				gbc_rdbtnCaulk.gridx = 1;
				gbc_rdbtnCaulk.gridy = 4;
				add(rdbtnCaulk, gbc_rdbtnCaulk);
				radioButtonGroup.add(rdbtnCaulk);
				
				rdbtnFerry = new JRadioButton("Pay a few dollars to take the ferry across");
				GridBagConstraints gbc_rdbtnFerry = new GridBagConstraints();
				gbc_rdbtnFerry.anchor = GridBagConstraints.WEST;
				gbc_rdbtnFerry.insets = new Insets(0, 0, 5, 5);
				gbc_rdbtnFerry.gridx = 1;
				gbc_rdbtnFerry.gridy = 5;
				add(rdbtnFerry, gbc_rdbtnFerry);
				radioButtonGroup.add(rdbtnFerry);
				
				btnCrossRiver = new JButton("Cross River");
				GridBagConstraints gbc_btnCrossRiver = new GridBagConstraints();
				gbc_btnCrossRiver.insets = new Insets(0, 0, 5, 5);
				gbc_btnCrossRiver.gridx = 1;
				gbc_btnCrossRiver.gridy = 7;
				add(btnCrossRiver, gbc_btnCrossRiver);
				
				btnMenu = new JButton("Menu");
				btnMenu.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						parentFrame.showMenu();
					}
				});
				GridBagConstraints gbc_btnMenu = new GridBagConstraints();
				gbc_btnMenu.insets = new Insets(0, 0, 0, 5);
				gbc_btnMenu.gridx = 1;
				gbc_btnMenu.gridy = 8;
				add(btnMenu, gbc_btnMenu);
				btnCrossRiver.addActionListener(new ActionListener() {
					
					public void actionPerformed(ActionEvent e) {
						if(rdbtnFord.isSelected()) game.crossRiver("Ford", currentRiver.getRiverName(), currentRiver.getDepth());
						else if(rdbtnCaulk.isSelected()) game.crossRiver("Caulk", currentRiver.getRiverName(), currentRiver.getDepth());
						else if(rdbtnFerry.isSelected()) game.crossRiver("Ferry", currentRiver.getRiverName(), currentRiver.getDepth());
						game.takeATurn(parentFrame.getPlayPanel());
						parentFrame.showPlayPanel();
					}
				});
	}
}//End of class